﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Lab3
{
    public abstract class Entity
    {
        public string Name { get; set; }
        public Vector3 Position { get; set; }
        public Matrix Rotation { get; set; }
        public float Scale { get; set; }
        public Model Model { get; set; }
        public Texture2D Texture { get; set; }
        public Matrix ObjectWorld = Matrix.Identity;

        protected Camera Camera;

        public Dictionary<string, Effect> Effects { get; set; }
        
        protected Entity(Camera camera)
        {
            Position = new Vector3(0,0,0);
            Rotation = Matrix.Identity;
            Scale = 1.0f;
            Camera = camera;
            Effects = new Dictionary<string, Effect>();
        }

        public BasicEffect SceneBasicEffects(BasicEffect _effect)
        {
            _effect.FogEnabled = true;
            _effect.FogColor = Color.White.ToVector3();
            _effect.FogStart = FogConstants.FogStart;
            _effect.FogEnd = FogConstants.FogEnd;

            _effect.EnableDefaultLighting();
            _effect.LightingEnabled = true; // turn on the lighting subsystem.
            _effect.DirectionalLight0.DiffuseColor = new Vector3(1, 1, 1); // a red light
            _effect.DirectionalLight0.Direction = new Vector3(1, 0, 0);  // coming along the x-axis
            _effect.DirectionalLight0.SpecularColor = new Vector3(0, 1, 0.5f); // with green highlights
           
            _effect.DirectionalLight1.Enabled = true;
            _effect.DirectionalLight2.Enabled = true;
            
            return _effect;
        }

        public virtual void Update(GameTime gt)
        {
            ObjectWorld = Matrix.CreateScale(Scale)*Rotation*Matrix.CreateTranslation(Position);
        }

        public abstract void Draw(int type);
    }
}
